/**
 * Description:
 * Class Name:PathTest
 * Date:2022/5/4 15:09
 *
 * @author LTisme
 * @version JAVA17
 */
package 疯狂Java讲义.第15章_输入输出._15_10_NIO2的功能和用法._15_10_1_Path_Paths和Files核心API;

import java.nio.file.Path;
import java.nio.file.Paths;

public class PathTest {
    public static void main(String[] args) throws Exception{
        // 以当前路径创建Path对象
        Path path = Paths.get(".");
        System.out.println("path里包含的路径数量：" + path.getNameCount());
        System.out.println("path的根路径：" + path.getRoot());

        Path absolute_path = path.toAbsolutePath();
        System.out.println("path的绝对路径为：" + absolute_path);
        System.out.println("path绝对路径的根路径为：" + absolute_path.getRoot());
        System.out.println("path的绝对路径所包含的路径数量为：" + absolute_path.getNameCount());
        // 通过索引获取绝对路径中所包含的路径
        System.out.println(absolute_path.getName(3));
        // 以多个String来构建Path对象，它会将多个字符串连缀成路径
        Path path2 = Paths.get("g:", "publish", "codes");
        System.out.println(path2);
    }
}
